package ${controllerPackageName};

import com.xtck.ha.common.core.constant.HttpStatus;
import com.xtck.ha.common.core.utils.poi.ExcelUtil;
import com.xtck.ha.common.core.web.controller.BaseController;
import com.xtck.ha.common.core.web.domain.AjaxResult;
import com.xtck.ha.common.core.web.page.TableDataInfo;
import ${entityPackageName}.${entityName};
import ${servicePackageName}.${serviceName};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 模型列表 controller
 *
 * @ClassName: ${controllerName}
 * @Description: 外部访问接口
 * @author ${authorName}
 * @date ${currentTime}
 */
@Api(tags = "${tabInfo.tableComment}管理")
@RestController
@RequestMapping("/${moduleName}/${entityName?uncap_first}")
public class ${controllerName} extends BaseController {

    @Autowired
    private ${serviceName} ${serviceName?uncap_first};


    @ApiOperation("分页查询${tabInfo.tableComment}列表")
    @GetMapping("/page")
    public AjaxResult page(${entityName} ${entityName?uncap_first})
    {
        startPage();
        List<${entityName}> list = ${serviceName?uncap_first}.selectTList(${entityName?uncap_first});
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setList(list);
        rspData.setMsg("查询成功");
        rspData.setTotal(${serviceName?uncap_first}.count(${entityName?uncap_first}));
        return AjaxResult.success(rspData);
    }

    @ApiOperation("列表查询${tabInfo.tableComment}")
    @GetMapping("/list")
    public List<${entityName}> list(${entityName} ${entityName?uncap_first})
    {
        List<${entityName}> list = ${serviceName?uncap_first}.selectTList(${entityName?uncap_first});
        return list;
    }

    @ApiOperation("导出${tabInfo.tableComment}列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ${entityName} ${entityName?uncap_first})
    {
        List<${entityName}> list = ${serviceName?uncap_first}.selectTList(${entityName?uncap_first});
        ExcelUtil<${entityName}> util = new ExcelUtil<>(${entityName}.class);
        util.exportExcel(response, list, "样例数据");
    }

    @ApiOperation("获取$${tabInfo.tableComment}详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(${serviceName?uncap_first}.selectTById(id));
    }

    @ApiOperation("新增$${tabInfo.tableComment}")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ${entityName} ${entityName?uncap_first})
    {
        return toAjax(${serviceName?uncap_first}.insertT(${entityName?uncap_first}));
    }

    @ApiOperation("修改${tabInfo.tableComment}")
    @PutMapping
    public AjaxResult update(@RequestBody ${entityName} ${entityName?uncap_first})
    {
        int i = ${serviceName?uncap_first}.updateT(${entityName?uncap_first});
        return toAjax(i);
    }

    @ApiOperation("删除${tabInfo.tableComment}")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(${serviceName?uncap_first}.deleteTByIds(ids));
    }





}
